#!/bin/sh
#
# Pre-Installation script for Ubuntu Linux
# Dot Hill Systems, Inc (C) 2012-2014
# Seagate Technology LLC (C) 2015-2017
# Copyright (C) 2017-2023, Advanced Micro Devices, Inc. All rights reserved.

#ADAPTER_COUNT=0

#if [ -d /sys/bus/pci/drivers/ahci ]; then
#    chmod 777 /sys/bus/pci/drivers/ahci/unbind
#    PCIADDRESS=`ls /sys/bus/pci/drivers/ahci/  |grep -e '^[0-9a-z][0-9a-z][0-9a-z][0-9a-z]:'`
#    ADAPTER_COUNT=`echo $PCIADDRESS | wc -w`
#    set $PCIADDRESS
#    for item
#    do
#        echo -n "$item" > /sys/bus/pci/drivers/ahci/unbind
#    done
#else
#    ADAPTER_COUNT=999
#fi

#if [ -d /sys/bus/pci/drivers/nvme ]; then
#    chmod 777 /sys/bus/pci/drivers/nvme/unbind
#    PCIADDRESS=`ls /sys/bus/pci/drivers/nvme/  |grep -e '^[0-9a-z][0-9a-z][0-9a-z][0-9a-z]:'`
#    ADAPTER_COUNT_NVME=`echo $PCIADDRESS | wc -w`
#    ADAPTER_COUNT=`expr "$ADAPTER_COUNT"+"$ADAPTER_COUNT_NVME"`
#    set $PCIADDRESS
#    for item
#    do
#        echo -n "$item" > /sys/bus/pci/drivers/nvme/unbind
#    done
#fi

#
# Not all flavors of Ubuntu are attaching to all controllers...
# This leads to a invalid ADAPTER_COUNT when spanning. Since
# we're unbinding everything we find, assume that the driver
# will find everything during it's probe() function...
#
#ADAPTER_COUNT=999

#
# There appears to be an issue where the unbind is taking longer
# than the loop/insmod which leads to no/missing adapters. Sleep
# to allow unbind to finish.
#
#sleep 20

if [ ! -e /sbin/insmod ]; then
   echo "Symbolically linking: /sbin/insmod"
   ln -s /bin/kmod /sbin/insmod
fi

#insmod /dd/rcraid.ko rc_adapter_count=$ADAPTER_COUNT
insmod /dd/rcraid.ko 


